package com.xyzwps.lib.express.router.ap;

import java.util.ArrayList;
import java.util.List;

public class Lines {
    private final List<String> text = new ArrayList<>();
    private final List<Integer> indents = new ArrayList<>();

    private int indent = 0;

    public Lines add(String line) {
        text.add(line);
        indents.add(indent);
        return this;
    }

    public Lines indentPP() {
        indent++;
        return this;
    }

    public Lines indentMM() {
        indent--;
        return this;
    }

    @Override
    public String toString() {
        var sb = new StringBuilder();
        for (int i = 0; i < text.size(); i++) {
            var it = text.get(i);
            if (it == null) {
                sb.append("\n");
            } else {
                sb.append("    ".repeat(Math.max(0, indents.get(i)))).append(it).append("\n");
            }
        }
        return sb.toString();
    }
}